<template>
	<view class="u-wrap">
		<view class="status"></view>
		<view class="nav">
			<view class="left" @click="toBack()">
				<image src="../../static/image/back.png" />
			</view>
			<view class="center">新增任务</view>
			<view class="right">
				<image src="../../static/image/7a6c14529f55e7906092a378d697bd4.png" />
			</view>
		</view>
		<view class="shift_one" @click="show=true">
			<view class="left">
				<view class="inlie">
					执行人:
				</view>
			</view>
			<view class="right">
				{{activeExecutor.phone==null||activeExecutor.phone=='undefind'||activeExecutor.phone==''?'请选择':activeExecutor.phone}}
				<u-action-sheet :actions="arrayPerson" @select="selectClick" :title="title" :show="show"
					@close="close()">
				</u-action-sheet>
			</view>
		</view>
		<view class="shift_one">
			<view class="left">
				<view class="inlie">
					任务月份
				</view>
			</view>
			<view class="right">
				<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="uni-input">{{date}}</view>
				</picker>
			</view>
		</view>
		<view class="shift_one">
			<view class="left">
				<view class="inlie">
					理发任务量
				</view>
			</view>
			<view class="right">
				<input type="text" placeholder="请输入" v-model="lfrw" maxlength="20" />
			</view>
		</view>
		<view class="shift_one">
			<view class="left">
				<view class="inlie">
					推广任务量
				</view>
			</view>
			<view class="right">
				<input type="text" placeholder="请输入" v-model="tgrw" maxlength="20" />
			</view>
		</view>
		<view class="shift_one">
			<view class="left">
				<view class="inlie">
					卫生任务量
				</view>
			</view>
			<view class="right">
				<input type="text" placeholder="请输入" v-model="wsrw" maxlength="20" />
			</view>
		</view>
		<view class="shift_one">
			<view class="left">
				<view class="inlie">
					任务说明
				</view>
			</view>
			<view class="right">
				<input type="text" placeholder="请输入" v-model="rwsm" maxlength="50" />
			</view>
		</view>
		<view class="addbank" @click="toAddTasks()">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			// const currentDate = this.getDate({
			// 	format: true
			// })
			return {
				title: '选择执行人',
				arrayPerson: [],
				activeExecutor: {}, //选中的执行人
				show: false,
				date: '请选择',
				lfrw: '',
				tgrw: '',
				wsrw: '',
				rwsm: '',
				yg_id: '',
				user: null,
				sex: '',
				name: '',
				touxiang: '',
				dqjs: '',
				mendian_id: ''




			}
		},
		onLoad() {
			var that = this;
			uni.getStorage({
				key: 'user_key',
				complete: function(res) {
					// console.log(666,res)
					that.yg_id = res.data.id;
					that.user = res.data;
					that.sex = res.data.sex;
					that.name = res.data.name;
					that.touxiang = res.data.touxiang;
					that.dqjs = res.data.role;
					that.mendian_id = res.data.mendian;
					that.getPersonData(that.yg_id);
				}
			})
		},
		computed: {
			startDate() {
				return this.getDate('start');

			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			//提交表单数据
			toAddTasks() {
				if (this.activeExecutor.id == '' || this.activeExecutor.id == 'undefind' || this.activeExecutor.id ==
					null) {
					uni.showToast({
						icon: 'none',
						position: 'center',
						title: "请选择执行人"
					});
					return;
				}
				if (this.date == '请选择') {
					uni.showToast({
						icon: 'none',
						position: 'center',
						title: "请选择任务月份"
					});
					return;
				}
				if (this.lfrw == '') {
					uni.showToast({
						icon: 'none',
						position: 'center',
						title: "请填写理发任务"
					});
					return;
				}
				if (this.tgrw == '') {
					uni.showToast({
						icon: 'none',
						position: 'center',
						title: "请填写推广任务"
					});
					return;
				}
				if (this.wsrw == '') {
					uni.showToast({
						icon: 'none',
						position: 'center',
						title: "请填写卫生任务"
					});
					return;
				}
				if (this.rwsm == '') {
					uni.showToast({
						icon: 'none',
						position: 'center',
						title: "请填写任务说明"
					});
					return;
				}
				let date = this.date.substring(0, 7)
				// console.log(222,this.activeExecutor.id)
				uni.request({
					url: getApp().globalData.url + '/client/AddRenwu',
					method: 'POST',
					data: {
						zxr: this.activeExecutor.id,
						yuef: date,
						lfrw: this.lfrw,
						tgrw: this.tgrw,
						wsrw: this.wsrw,
						rwsm: this.rwsm
					},
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					success: function(res) {
						// console.log(111,res)
						if (res.data.code == 200 && res.data.msg == '添加成功') {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "提交成功"
							});
						} else {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "请求出现异常！"
							});
						}
					}
				})
			},
			bindDateChange: function(e) {
				this.date = e.target.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			//获取管理名下员工数据
			getPersonData(id) {
				let _that = this;
				wx.request({
					url: getApp().globalData.url + '/client/GetMxus',
					method: 'GET',
					data: {
						id: id
					},
					header: {
						"Content-Type": "application/json"
					},
					success: function(res) {
						// console.log(555,res)
						if (res.data.code == 200 && res.data.msg == '查询成功') {
							_that.arrayPerson = res.data.data
						} else {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "请求出现异常！"
							});
						}
					}
				})
			},
			selectClick(index) {
				console.log(index)
				this.activeExecutor = index
				this.show = false
			},
			close() {
				this.show = false
			},


		}
	}
</script>
<style>
	page {
		background: #F0F0F0;
		height: auto;
		min-height: 100%;
	}
</style>
<style scoped lang="scss">
	.u-wrap {
		text-align: center;
		align-items: center;
		padding-bottom: 280rpx;

		.status {
			height: var(--status-bar-height);
			background-color: #1BB68E;

		}

		.nav {
			display: flex;
			justify-content: space-between;
			height: 73rpx;
			background-color: #1BB68E;

			.left {
				width: 33%;
				height: 73rpx;
				text-align: left;
				align-items: center;

				image {
					width: 20rpx;
					height: 33rpx;
					margin-left: 29rpx;
					margin-top: 20rpx;

				}
			}

			.center {
				width: 33%;
				align-items: center;
				height: 73rpx;
				color: #fff;
				font-size: 36rpx;
				font-weight: bold;
				line-height: 73rpx;

			}

			.right {
				width: 33%;
				height: 73rpx;
				text-align: right;
				margin-right: 30rpx;

				image {
					width: 12rpx;
					height: 34rpx;
					margin-top: 30rpx;
				}
			}
		}

		.shift_one {
			margin-top: 20rpx;
			margin-right: 20rpx;
			min-height: 80rpx;
			display: flex;
			border: 1rpx solid #D3D3D3;
			border-radius: 16rpx;
			margin-left: 20rpx;
			background-color: #fff;

			.left {
				height: 80rpx;
				width: 20%;
				margin: auto 15rpx;
			}

			.right {
				width: 80%;
				height: 80rpx;
				text-align: left;
				color: #989EB8;
				line-height: 80rpx;
				padding-top: 35rpx;
				margin-left: 10rpx;

				input {
					height: 60rpx;
					width: 100%;

					margin-top: 10rpx;
				}
			}

			.right_one {
				width: 80%;
				height: 80rpx;
				text-align: left;
				color: #989EB8;
				padding-top: 35rpx;
				margin-left: 10rpx;

				.rich {
					height: 80rpx;
					border: 1rpx solid #FF226F;
				}
			}

		}

		.shift_one {
			margin-top: 20rpx;
			margin-right: 20rpx;
			min-height: 100rpx;
			display: flex;

			.left {
				height: 100rpx;
				width: 20%;
				margin: auto 15rpx;

				.inlie {
					height: 60rpx;
					width: auto;
					border-radius: 50rpx;
					background-color: #FF037E;
					color: #FFFFFF;
					font-size: 26rpx;
					line-height: 60rpx;
					margin-top: 20rpx;
				}
			}

			.right {
				min-height: 100rpx;
				width: 80%;
				display: flex;
				flex-wrap: wrap;
				align-content: flex-start;
				padding-bottom: 15rpx;
				border-radius: 16rpx;

				.picker {
					line-height: 100rpx;
					color: #989EB8;
				}
			}
		}

		.addbank {
			height: 100rpx;
			border-radius: 50rpx;
			color: #FFFFFF;
			font-size: 36rpx;
			background-color: #36D28E;
			line-height: 100rpx;
			position: fixed;
			right: 0;
			left: 0;
			bottom: 0;
			margin: auto 41rpx 100rpx 40rpx;
		}


	}
</style>
